package org.gitos.cloud.server.mq;

import com.alibaba.fastjson.JSON;
import org.gitos.cloud.domain.comm.Constant;
import org.gitos.cloud.domain.mq.MqTools;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Configurable;
import org.springframework.stereotype.Component;

@Component
@Configurable
public class PushManager {

    private static final Logger log = LoggerFactory.getLogger(PushManager.class);

    @Autowired
    private AmqpAdmin rabbitAdmin;
    @Autowired
    private RabbitTemplate rabbitTemplate;

    public void sendMsg(String routeKey, Object obj) {
        MqTools.bindDirect(routeKey, Constant.COMET_EXCHANGE, rabbitAdmin);
        rabbitTemplate.convertAndSend(Constant.COMET_EXCHANGE, routeKey,
                JSON.toJSONString(obj));
    }
}
